package com.ee.lock.service;

import cn.hutool.core.lang.Snowflake;
import com.ee.lock.dao.LockMapper;
import com.ee.lock.entity.Lock;
import com.ee.lock.utills.ResultBody;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LiBo
 * @date 2022年03月02日 15:41
 */

@Service
public class LockService {
    @Resource
    LockMapper lockMapper;

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public String addLock(String telephone){

        Snowflake snowflake = new Snowflake(0, 0);
        Lock lock = new Lock();
        lock.setId(snowflake.nextIdStr());
        lock.setTelephone(telephone);
        lockMapper.addLock(lock);
        return lock.getId();
    }

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public List<Lock> getAllLock(){
        return lockMapper.getLock();
    }

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public int updateStatus(String id, Integer status){
        return lockMapper.updateStatus(id, status);
    }
}
